// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var css_main = require("./account.css");
	var constant = require("constant");
	var databind = require("databind");
	var dialog = require("dialog");
	var tools = require("tools");
	var _css = require("./warehousePickupList2.css");
	var html_financeContract = require("./html_financeContract.html");
	var html_cancelApplication = require("./html_cancelApplication.html");
	var html_verify = require("../apply/apply_verify.html");
	var html_bailReturn = require("./html_bailReturn.html");
	var pickupState;
	var productTypes=0;
	var applytypes;
	var enterpriseName;
	var isProviders=false;
	var financeId;
	var type;
	var financeState;
	var productType;
	var financeNumber;
	var enterpriseId;
	var supervisionQuantity=0;
	var financeAmount;
	var storage = window.sessionStorage;
	var p1 = 0;
	var p2 = 0;
	var p3 = 0;
	var p4 = 0;
	var p5 = 0;
	var oData = {};
	var pageIndex = 1,
	pageSize = 1000,
	totalPageCount = 1,
	totalRecordCount = 0; //分页初始化
	
	var init = function(page) {
		p1 = 0;
		p2 = 0;
		p3 = 0;
		p4 = 0;
		p5 = 0;
		$("#warehousePickupList2 .pickupQuantitys").html(0);
		$("#warehousePickupList2 .bulkstockAmount").html(0);
		$("#warehousePickupList2 .interest").html(0);
		$("#warehousePickupList2 .others").html(0);
		$("#warehousePickupList2 .pickupAmounts").html(0);
		var oData = {
			pageIndex : 1,
	        pageSize : 1000,
	        totalPageCount : 1,
	        totalRecordCount : 0,//分页初始化
	        productType:productTypes,
	        isProvider:1,
	        pickupState: eval ("(" + pickupState + ")")
		};
		financeId = page.params.financeId;
		type = page.params.type;
		storage.setItem("financeId", financeId);
//		pickupState = page.params.pickupState || base.getUrlParam("pickupState");
		oData.financeId=financeId;
		inquireFinancePickupApplicationWarehousePageList1(oData);
		inquireFinanceApplicationDetail();
		$(".d2 a").removeClass("active_tab");
		$(".warehousePickups").addClass("active_tab");
		$(".accountDetail").parent().parent().addClass("active_tab4");
		$(".accountDetail").parent().parent().removeClass("active_tab1");
		$(".accountDetail").parent().parent().removeClass("active_tab2");
		$(".accountDetail").parent().parent().removeClass("active_tab3");
		router.init();
//		inquireCurrentEnterpriseDetail();
		initEvent();
	};
	var initEvent = function() {
			if (pickupState != null) {
				$("#warehousePickupList2 select[name=pickupState]").html("<option value='"+pickupState+"'>待办</option><option value=''>全部</option>");
			} else {
				
			}
//			tools.loadSelectList($("#warehousePickupList2 select[name=enterpriseId]"), "inquireEnterpriseList.json", "id", "name", null);
//			$("#pp1").hide();
		
		//融资证明材料
		$(".accountMaterial").unbind("click").click(function() {
			router.route("account/accountDetailMaterial.html?financeId=" + financeId + "&type="+type);
		});

		//融资动态
		$(".accountProcess").unbind("click").click(function() {
			router.route("account/accountDetailProcess.html?financeId=" + financeId + "&type="+type+ "&enterpriseId=" +enterpriseId +"&enterpriseName="+enterpriseName+"&productType="+productType);
		});

		//提货列表
		$(".warehousePickups").unbind("click").click(function() {
			router.route("account/warehousePickupList2.html?financeId=" + financeId + "&type="+type);
		});
		//融资项目信息
		$(".accountDetail").unbind("click").click(function(){
			router.route("account/accountDetail.html?financeId="+financeId + "&type="+type);
		});
	};
	//提交融资申请
	var submitFinanceApplication = function() {
		base.fnAjax({
			action: "submitFinanceApplication.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					router.route("account/accountMain.html");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//取消融资申请
	var cancelFinanceApplication = function() {
		base.fnAjax({
			action: "cancelFinanceApplication.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功！");
					dialog.hideDialog($("#applyVerify"));
					router.route("account/accountMain.html");
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	//查询评价信息
	var inquireFinanceEvaluate = function() {
		base.fnAjax({
			action: "inquireFinanceEvaluate.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (data.datas[0].content == "") {
						$(".buttonOperate").html("评价").attr("id", "evalute");
					} else {
						$(".buttonOperate").remove();
					}
				} else {
					$(".buttonOperate").html("评价").attr("id", "evalute");
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	//货物一览
	var bulkstockListing = function() {
		router.route("account/accountBulkstockListing.html?financeId=" + financeId + "&productType=" + productType);
	}
	//融资评价
	var evaluteFinanceApplication = function() {
		router.route("account/accountEvaluate.html?financeId=" + financeId);
	}
	//合同一览
	var documentSign = function() {
		router.route("account/documentSign.html?financeId=" + financeId+"&financeState="+financeState);
	}
	var showEvaluteDetail = function(){
		router.route("account/accountEvaluateDetail.html?financeId="+financeId);
	}
	//额度处理
	var verifyFinanceApplication = function() {
		$("#popdialog").html(html_verify);
		dialog.showDialog($("#applyVerify"));
		$(".financeNumber").html(financeNumber);
		$(".financeAmount").html("￥" + financeAmount);

		databind.fillInput($("#applyVerify"), {
			action: "inquireCurrentEnterpriseDetail.json",
			version: "v1.0"
		});
		$("#verifySure").unbind("click").click(function() {
			consentFinanceAuditAmountApplication();
		});

		$("#verifyCancel").unbind("click").click(function() {
			cancelFinanceApplication();
		});
	}

	//接受融资审批金额
	var consentFinanceAuditAmountApplication = function() {
		base.fnAjax({
			action: "consentFinanceAuditAmountApplication.json",
			async: false,
			oData: {
				financeId: financeId
			},
			fnSuccess: function(data) {
				tools.cancelProtectDoubleClick();
				if (data.status == 200) {
					base.alert(1, "操作成功！");
					dialog.hideDialog($("#applyVerify"));
					router.route("account/accountMain.html");
				} else {
					base.alert(2, "数据获取失败");
				}
			}
		});
	};
	//提货申请
	var pickupFinanceApplication = function() {
		router.route("account/accountPickup.html?financeId=" + financeId + "&financeNumber=" + financeNumber);
	}
	//修改融资申请
	var updateFinanceApplication = function() {
		location.href = "../apply/apply_main.html?financeId=" + financeId + "&productType=" + productType;
	}
	
	//查询所需附件列表
	var inquireFinanceFilesNormList = function() {
		base.fnAjax({
			action: "inquireFinanceFilesNormList.json",
			async: false, //同步异步
			oData: {
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $(".html_financeContract script").html();
					var html = juicer(tpl, data);
					$(".html_financeContract .normInfos").html(html);
					
					for (var i = 0; i < $(".html_financeContract .normFileName").length; i++) {
						var $this = $("#" + $($(".html_financeContract .normFileName")[i]).attr("id"));
						tools.fileupload($this, null, function (data, dom) {
							var d = $("#" + $(dom).attr("id"));
							var str = '<tr fileUuid="'+data.result.data[0].fileUuid+'" class="mas"><td class="fileIndex"></td><td>'+data.result.data[0].fileName+'</td><td>'+d.parent().find("input[name=filesUuid]").attr("codeName")+'</td><td><input type="checkbox" value="1" /></td><td><a href="/finance/api/v1.0/viewPdfFile.json?fileUuid=' + data.result.data[0].fileUuid + '" target="_blank">预览</a> <a href="javascript:void(0);" class="deleteProductIntro">删除</a></td></tr>';
							d.parent().find("table").append(str);
							var fileUuid = [];
							var fileSign = [];
							for (var j = 0; j < d.parent().find(".mas").length; j++) {
								fileUuid.push($(d.parent().find(".mas")[j]).attr("fileUuid"));
								$(d.parent().find(".mas")[j]).find(".fileIndex").html(j+1);
								if ($(d.parent().find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.parent().find("input[name=filesUuid]").val(fileUuid);
							d.parent().find("input[name=filesSign]").val(fileSign);
						});
					};
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//提交提货
	var submitFinancePickupApplicationWarehouse = function(pickupId, callback) {
		base.fnAjax({
			action: "submitFinancePickupApplicationWarehouse.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "提交成功！");
					router.route("account/warehousePickupList.html");
				}else {
					base.alert(3, data.message);
				}
				callback();
			}
		});
	};
	//取消提货
	var cancelFinancePickupApplicationWarehouse = function(pickupId, callback) {
		base.fnAjax({
			action: "cancelFinancePickupApplicationWarehouse.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "取消成功！");
					router.route("account/warehousePickupList2.html?financeId="+financeId);
				}else {
					base.alert(3, data.message);
				}
				callback();
			}
		});
	};
	
	//合同提交
	var submitPickupContract = function(pickupId) {
		base.fnAjax({
			action: "submitPickupContract.json",
			async: false,
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "提交成功！");
					router.route("account/warehousePickupList.html");
				}else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//查询企业详情
//	var inquireCurrentEnterpriseDetail = function() {
//		base.fnAjax({
//			action: "inquireCurrentEnterpriseDetail.json",
//			nocode: true,
//			oData: {
//			
//			}, //传递参数
//			fnSuccess: function(data) {
//				if (data.status == 200) {
//					enterpriseName = data.datas[0].enterpriseName;	
//				}else {
//				}
//			}
//		})
//	};
	
	//加载提货列表
	var inquireFinancePickupApplicationWarehousePageList1 = function(oData) {
		base.fnAjax({
			action: "inquireFinancePickupApplicationWarehousePageList1.json",//inquireFinanceApplicationList
			async: false,
			oData: oData, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					
					oData.totalPageCount = data.totalPageCount;
					oData.totalRecordCount = data.totalRecordCount;
					
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#warehousePickupList2 #warehouseUpInfoTmpl").html();
					var html = juicer(tpl, data);
					$("#warehousePickupList2 .outerTable").append(html);
					
					for(var i = 0; i < $("#warehousePickupList2 .index").length; i++) {
						$("#warehousePickupList2 .index")[i].innerHTML = i+1;
					}
					
					$(".loadMore").unbind("click").click(function(){
						$(".sumInfo").remove();
						if (oData.pageIndex < data.totalRecordCount) {
							oData.pageIndex = oData.pageIndex*1+1;
						}
						inquireFinancePickupApplicationWarehousePageList1(oData);
					});
					
					$(".loadAll").unbind("click").click(function(){
						p1 = 0;
						p2 = 0;
						p3 = 0;
						p4 = 0;
						p5 = 0;
						var s = '<tr style="border-bottom: solid 1px #CCC;">'+
						'	<th>No</th>'+
						'	<th class="none">融资编号</th>'+
						'	<th class="none">业务类型</th>'+
						'	<th>货物名称</th>'+
						'	<th>仓库</th>'+
						'	<th class="none">剩余监管量(吨)</th>'+
						'	<th>提货量(吨)</th>'+
						'	<th>本金(元)</th>'+
						'	<th>服务费(元)</th>'+
						'	<th>其他(元)</th>'+
						'	<th>总金额(元)</th>'+
						'	<th>状态</th>'+
						'	<th>操作</th>'+
						'</tr>'+
						'<tr style="border: none;">'+
						'	<td style="padding: 5px 0; border: none;" colspan="13" style="border: none;"></td>'+
						'</tr>';
						$("#warehousePickupList2 .outerTable").html(s);
						
						oData.pageIndex = 1;
						oData.pageSize = 100000;
						inquireFinancePickupApplicationWarehousePageList1(oData);
					});
					
					$.each(data.datas, function() {
						var _this1 = this;
						if (_this1.pickupState != 1 && _this1.pickupState != 13) {
							$.each(_this1.bulkstockList, function() {
								var _this2 = this;
								p1 = _this2.pickupQuantity*1 + p1*1;
								p2 = _this2.bulkstockAmount*1 + p2*1;
								p3 = _this2.interest*1 + p3*1;
								p4 = _this2.others*1 + p4*1;
								p5 = _this2.pickupAmount*1 + p5*1;
							});
						}
					});
					$("#warehousePickupList2 .pickupQuantitys").html(tools.formatCurrency(p1.toFixed(2)));
					$("#warehousePickupList2 .bulkstockAmount").html(tools.formatCurrency(p2.toFixed(2)));
					$("#warehousePickupList2 .interest").html(tools.formatCurrency(p3.toFixed(2)));
					$("#warehousePickupList2 .others").html(tools.formatCurrency(p4.toFixed(2)));
					$("#warehousePickupList2 .pickupAmounts").html(tools.formatCurrency(p5.toFixed(2)));
					
					//新增代销提货
					$("#warehousePickupList2 .createPickup").unbind("click").click(function(){
						router.route("account/createPickup.html");
					});
					//新增代采提货
					$("#warehousePickupList2 .createPickup1").unbind("click").click(function(){
						router.route("account/createPickup1.html");
					});
					//初审
					$("#warehousePickupList2 .audit").unbind("click").click(function(){
						router.route("warehousePickup/approvelConsignment.html?pickupId="+ $(this).parents("tr").attr("pickupId"));
					});
					
					//政审
					$("#warehousePickupList2 .careful").unbind("click").click(function(){
						router.route("warehousePickup/approvelCarefulManage.html?pickupId="+ $(this).parents("tr").attr("pickupId"));
					});
					
					//详情
					$("#warehousePickupList2 .details").unbind("click").click(function(){
						var productType = $(this).parents("tr").attr("productType");
						if(productType == 6) { //代销提货
							router.route("account/createPickupDetaild.html?pickupId=" + $(this).parents("tr").attr("pickupId") + "&financeId=" + $(this).parents("tr").attr("financeId"));
						}else if(productType == 5) { //代采提货
							router.route("account/createPickupDetailc2.html?pickupId=" + $(this).parents("tr").attr("pickupId") + "&financeId=" + $(this).parents("tr").attr("financeId"));
						}
					});
					
					//修改
					$("#warehousePickupList2 .update_s2").unbind("click").click(function(){
						var productType = $(this).parents("tr").attr("productType");
						var enterpriseName=$(this).parents("tr").attr("enterpriseNames");
						var buyer=$(this).parents("tr").attr("buyer");
						if(productType == 6) { //代销提货
							router.route("account/updatePickupd3.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
						}else if(productType == 5) { //代采提货
							router.route("account/updatePickupc1.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
						}
					});
					
					//平台签署
					$("#warehousePickupList2 .platformSign").unbind("click").click(function(){
						var $this = $(this);
						
						ii = layer.open({
						  title: '合同信息',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_documentSign,
						  btn: ['确定']
						});
						
						inquireFinancePickupApplicationWarehouse1($this.parents("tr").attr("pickupId"));
					});
					//合同签署
					$("#documentSign_s3").unbind("click").click(function(){
						router.route("account/warehousePickupdocumentSign.html?pickupId=" + $(this).parents("tr").attr("pickupId"));
		        	});
					// 点击合同确认
					$("#warehousePickupList2 .contractConfirm").unbind("click").click(function() {
						var $this = $(this);
						ii = layer.open({
						  type: 1,
						  title: "合同确认",
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_contractConfirm,
						  btn: ['确定'],
						  yes: function(){
						  	if ($(".confirm").length > 0) {
						  		base.alert(2, "还有合同尚未确认！");
						  		return false;
						  	} else {
						  		layer.close(ii);
						  		loadPickupList(oData);
						  	}
						  },
						  cancel: function(){
						  	if ($(".confirm").length > 0) {
						  		base.alert(2, "还有合同尚未确认！");
						  		return false;
						  	} else {
						  		layer.close(ii);
						  		loadPickupList(oData);
						  	}
						  }
						});
						
						
						inquireFinancePickupApplicationWarehouse2($this.parents("tr").attr("pickupId"));
					});
					
					//提交提货
					$("#warehousePickupList2 .submitApplication").unbind("click").click(function(){
						var $this = $(this);
						var ii = layer.confirm('是否确认提交该条提货', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							submitFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
								layer.close(ii);
								loadPickupList(oData);
							});
						});
					});
					$("#warehousePickupList2 .cancel_01").unbind("click").click(function(){
						var $this = $(this);
						var ii = layer.confirm('是否确认取消该条提货', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							cancelFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
								layer.close(ii);
							});
						});
					});
					
					//合同提交
					$("#warehousePickupList2 .submit").unbind("click").click(function(){
						var $this = $(this);
						var ii = layer.confirm('是否确认提交合同', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							submitPickupContract($this.parents("tr").attr("pickupId"), function(){
								layer.close(ii);
							});
						});
					});
					
					//合同上传
					$("#warehousePickupList2 .upload").unbind("click").click(function(){
						var $this = $(this);
						var ii = layer.open({
						  title: '上传合同',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['1000px', '600px'], //宽高
						  content: html_financeContract,
						  btn: ['确定', '取消'],
						  yes: function(){
						  		databind.submitDom($(".html_financeContract"), function(){
							  		layer.msg("提交成功！");
							  		layer.close(ii);
							  		loadPickupList(oData);
							  	});
						  }
						});
						$(".html_financeContract input[name=pickupId]").val($this.parents("tr").attr("pickupId"));
						if ($(this).parents("tr").attr("pickupState") == 3) {
							inquireFinanceFilesNormList();
						} else {
							$(".html_financeContract").attr("action", "updateWarehousePickupContract");
							inquireFinancePickupApplicationWarehouse($this.parents("tr").attr("pickupId"));
						}
						
						$(".html_financeContract").on("click", ".deleteProductIntro", function() {
							var d = $(this).parent().parent().parent().parent().parent();
							$(this).parents("tr").remove();
							var fileUuid = [];
							var fileSign = [];
							for (var j = 0; j < d.find(".mas").length; j++) {
								fileUuid.push($(d.find(".mas")[j]).attr("fileUuid"));
								$(d.find(".mas")[j]).find(".fileIndex").html(j+1);
								if ($(d.find(".mas")[j]).find("input[type=checkbox]").prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.find("input[name=filesUuid]").val(fileUuid);
							d.find("input[name=filesSign]").val(fileSign);
						});
						
						$(".html_financeContract").on("click", "table input[type=checkbox]", function() {
							var d = $(this).parent().parent().parent().parent().parent();
							var fileSign = [];
							for (var j = 0; j < d.find("input[type=checkbox]").length; j++) {
								if ($(d.find("input[type=checkbox]")[j]).prop("checked")) {
									fileSign.push(1);
								} else {
									fileSign.push(0);
								}
							}
							d.find("input[name=filesSign]").val(fileSign);
						});
					});
					
					//解除监管
					$("#warehousePickupList2 .release").unbind("click").click(function(){
						var $this = $(this);
						var ii = layer.confirm('是否确认解除监管', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							deregulationPickupApplicationWarehouse($this.parents("tr").attr("pickupId"), function(){
								layer.close(ii);
							});
						});
					});
					if(data.datas.length >0){
						supervisionQuantity=data.datas[0].bulkstockList[0].supervisionQuantity;
					}
					var supervisionQuantitys = 0;
					$.each($("#createPickupDetail .supervisionQuantity"), function() {
						supervisionQuantitys += parseFloat($(this).attr("supervisionQuantity"));
					});
					$("#createPickupDetail #supervisionQuantitys").html(tools.formatCurrency(supervisionQuantitys.toFixed(2)));
					
					var pickupQuantitys = 0;
					$.each($("#createPickupDetail .pickupQuantity"), function() {
						pickupQuantitys += parseFloat($(this).attr("pickupQuantity"));
					});
					$("#createPickupDetail #pickupQuantitys").html(tools.formatCurrency(pickupQuantitys.toFixed(2)));
					
					var bulkstockAmount = 0;
					$.each($("#createPickupDetail .bulkstockAmount"), function() {
						bulkstockAmount += parseFloat($(this).attr("bulkstockAmount"));
					});
					$("#createPickupDetail #bulkstockAmount").html(tools.formatCurrency(bulkstockAmount.toFixed(2)));
					
					var interest = 0;
					$.each($("#createPickupDetail .interest"), function() {
						interest += parseFloat($(this).attr("interest"));
					});
					$("#createPickupDetail #interest").html(tools.formatCurrency(interest.toFixed(2)));
					
					var others = 0;
					$.each($("#createPickupDetail .others"), function() {
						others += parseFloat($(this).attr("others"));
					});
					$("#createPickupDetail #others").html(tools.formatCurrency(others.toFixed(2)));
					
					var pickupAmounts = 0;
					$.each($("#createPickupDetail .pickupAmount"), function() {
						pickupAmounts += parseFloat($(this).attr("pickupAmount"));
					});
					$("#createPickupDetail #pickupAmounts").html(tools.formatCurrency(pickupAmounts.toFixed(2)));
				
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//查询融资信息详情
	var inquireFinanceApplicationDetail = function() {
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",//inquireFinanceApplicationList
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("formatCurrency", tools.formatCurrency);
					juicer.register("getValueByKey", constant.getValueByKey);
					juicer.register("addDate", tools.addDate);
					if (data.datas[0].productId != null && data.datas[0].productId != 0) {
						data.datas[0].bailRate = inquireFinanceProductDetail(data.datas[0].productId);
					}
					var tpl = $("#warehouseUpInfoTmpl_s2").html();
					var html = juicer(tpl, data);
					$("#warehousePickupList2 .content2").html(html);
					$("#warehousePickupList2 input[name=supervisionQuantity]").val(supervisionQuantity+"吨");
					financeState = $("#financeState").val();
					enterpriseId=data.datas[0].enterpriseId;
					enterpriseName=data.datas[0].enterpriseName;
					productType=data.datas[0].productType;
					financeNumber=data.datas[0].financeNumber;
					financeAmount=data.datas[0].financeAmount;
//					if(productType == 2){
//						if (financeState == 1) {
//							
//						} else if (financeState == 2) {
//							$(".buttonOperate2").html("额度处理").attr("id", "verifyApply4").removeClass("none");
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="cancelApply4">取消申请</a>');
//						} else if (financeState == 4) {
//							$(".buttonOperate2").html("修改").attr("id", "modifyApply4").removeClass("none");
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="cancelApply4">取消申请</a>');
//						} else if (financeState == 17) {
//							inquireFinanceEvaluate();
//						} else if (financeState == 18) {
//							$(".buttonOperate2").html("评价").attr("id", "evalute4").removeClass("none");
//						} else if (financeState == 19) {
//							$(".buttonOperate2").html("评价信息").attr("id", "evaluteDetail4").removeClass("none");
//						} else if (financeState == 20) {
//							$(".buttonOperate2").html("取消申请").attr("id", "cancelApply4").removeClass("none");
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="modifyApply4">修改</a>');
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="submitApply4">提交融资</a>');
//						} else {
//							$(".buttonOperate2").hide();
//						}
//						
//						if (data.datas[0].bail - data.datas[0].bailAlreadyReturn > 0) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="bailReturn4">退还保证金</a>');
//						}
//						if (financeState > 5) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="bulkstockListing4">货物一览</a>');
//						}
//						if (financeState == 24 || financeState == 23 || financeState == 22) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="documentSign4">合同签署</a>');
//						}
//	
//						if (financeState >= 6) {
//							$(".exceptionOperate").removeClass("none");
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="pickupApply4">申请提货</a>');
//						}
//					}else 
						if(productType == 6){
//						if (data.datas[0].bail - data.datas[0].bailAlreadyReturn > 0) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="bailReturn4">退还保证金</a>');
//						}
//						if (financeState > 5) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="bulkstockListing4">货物一览</a>');
//						}
//						if (financeState == 24 || financeState == 23 || financeState == 22) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="documentSign4">合同签署</a>');
//						}
	
						$(".buttonOperate2:first").before('<a class="buttonOperate2" id="createPickup11_s">提货</a>');
					}else if(productType == 5){
//						if (financeState > 5) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="bulkstockListing4">货物一览</a>');
//						}
//						if (financeState == 24 || financeState == 23 || financeState == 22) {
//							$(".buttonOperate2:first").before('<a class="buttonOperate2" id="documentSign4">合同签署</a>');
//						}
	
						$(".buttonOperate2:first").before('<a class="buttonOperate2" id="createPickup11_s">提货</a>');
					}
					
//					$(".buttonOperate2:first").before('<a class="buttonOperate2" id="calcelApply4">融资申请取消</a>');
					
					databind.disableInput(".content2");
					$("#calcelApply4").unbind("click").click(function(){
						var ii = layer.open({
						  title: '融资取消申请',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['800px', '300px'], //宽高
						  content: html_cancelApplication,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".createFinanceCancelApplication"), function(){
						  		layer.msg("申请成功！");
						  		layer.close(ii);
						  		router.route("account/accountDetail.html?financeId=" + financeId);
						  	});
						  }
						});
						
						$(".createFinanceCancelApplication input[name=financeId]").val(financeId);
					});
					//取消融资
					$("#cancelApply4").unbind("click").click(function() {
						dialog.showConfirmDialog("取消融资", "是否确定取消融资？", function(){
							cancelFinanceApplication();
						});
					});
					//提交融资
					$("#submitApply4").unbind("click").click(function() {
						dialog.showConfirmDialog("提交融资", "提交以后不能再次修改,是否确定提交融资？", function(){
							submitFinanceApplication();
						});
					});
					
					$("#verifyApply4").unbind("click").click(function() {
						verifyFinanceApplication();
					});
					
					//修改融资
					$("#modifyApply4").unbind("click").click(function() {
						updateFinanceApplication();
					});
					//评价
					$("#evalute4").unbind("click").click(function() {
						evaluteFinanceApplication();
					});
					//货物一览
					$("#bulkstockListing4").unbind("click").click(function() {
						bulkstockListing();
					});
					//合同一览
					$("#documentSign4").unbind("click").click(function() {
						documentSign();
					});
					//保证金退还
					$("#bailReturn4").unbind("click").click(function() {
						var ii = layer.open({
						  title: '保证金退还',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['300px', '150px'], //宽高
						  content: html_bailReturn,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".createBailReturn"), function(){
						  		layer.msg("申请成功！");
						  		layer.close(ii);
						  	});
						  }
						});
						$(".createBailReturn input[name=financeId]").val(financeId);
						tools.clearNoNumAll($(".createBailReturn"));
					});
					//提货
					$("#createPickup11_s").unbind("click").click(function(){
						if(productType == 5){
							router.route("account/createPickup6.html?enterpriseId=" + enterpriseId +"&financeNumber=" + financeNumber+"&enterpriseName="+enterpriseName+"&productType="+productType+"&financeId="+financeId);
						}else if(productType == 6){
							router.route("account/createPickup4.html?enterpriseId=" + enterpriseId +"&financeNumber=" + financeNumber+"&enterpriseName="+enterpriseName+"&productType="+productType+"&financeId="+financeId);
						}
						
					});
					//查看评价信息
					$("#evaluteDetail4").unbind("click").click(function() {
						showEvaluteDetail();
					});
					//提货申请
					$("#pickupApply4").unbind("click").click(function() {
						pickupFinanceApplication();
					});
				} else {}
			}
		});
	};

	
	return {
		init: init
	};
});